package cn.qf.web;


import cn.qf.pojo.PageBean;
import cn.qf.pojo.User;
import cn.qf.service.UserService;
import cn.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class FindUserByPageService extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //接收参数并进行判断,给定默认值
        //currentPage /pageSize两个参数
        String curPage = req.getParameter("currentPage");
        String pSize = req.getParameter("pageSize");
        if(curPage== null || curPage.equals("")){
            //默认值
            curPage= "1" ;//第一页
        }
        if(pSize== null || pSize.equals("")){
            pSize = "2" ; //每页显示2条
        }

        //类型转换
        int currentPage = Integer.parseInt(curPage) ;
        int pageSize = Integer.parseInt(pSize) ;

        //调用用户业务接口
        UserService userService = new UserServiceImpl() ;
        PageBean<User> pb= userService.findUserByPage(currentPage,pageSize);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
